home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / netman.arc / FOLLOWER.PAS next >
Pascal/Delphi Source File  |  1989-06-30  |  8KB  |  479 lines

  1. {$ifdef CPU87}
  2.   {$N+}
  3. {$endif}
  4.  
  5. program Follower;
  6.  
  7. uses Graph, Crt, Drivers, Fonts;
  8.  
  9. const Choir = 5;
  10.       Bass = 200;
  11.       Treble = 1500;
  12.       Tempo = 2;
  13.       Rhythm = 40;
  14.       Path='.';
  15.       Painting = 'FRACTAL.DAT';
  16.       Framework = 'VALUES.DAT';
  17.  
  18. const No_Error = $00;
  19.       Not_Found = $02;
  20.       Access_Denied = $05;
  21.  
  22. const Read_Only = $00;
  23.       Write_Only = $01;
  24.       Read_Write = $02;
  25.       Deny_All = $10;
  26.       Deny_Write = $20;
  27.       Deny_Read = $30;
  28.       Deny_None = $40;
  29.  
  30. type Count_Type = byte;
  31.      Size_Type = word;
  32.  
  33. {$ifdef CPU87}
  34.      Real_Type = single;
  35. {$else}
  36.      Real_Type = real;
  37. {$endif}
  38.  
  39. type Header = record
  40.                 Sound: boolean;
  41.                 AtV,
  42.                 ToV: Size_Type;
  43.               end;
  44.  
  45. type Shape = record
  46.                Flux: Header;
  47.                H,
  48.                V: Size_Type;
  49.                Most: Count_Type;
  50.                BitPixel,
  51.                PixelByte: byte;
  52.                ByteLine: word;
  53.                Top,
  54.                Left,
  55.                YInc,
  56.                XInc: Real_Type;
  57.                Interlace: boolean;
  58.              end;
  59.  
  60. var PriorExit: pointer;
  61.  
  62. {$f+}
  63. procedure Terminate;
  64. {$f-}
  65.  
  66. begin
  67. CloseGraph;
  68. ExitProc:=PriorExit;
  69. end;
  70.  
  71. const Colors = 3;
  72.  
  73. procedure Initiate;
  74.  
  75. const Mode: integer = CGAC0;
  76.       Device: integer= CGA;
  77.  
  78. var Result: integer;
  79.  
  80. begin
  81. Result:=RegisterBGIdriver(@CGADriverProc);
  82. InitGraph(Device, Mode, Path);
  83. Result:=RegisterBGIfont(@GothicFontProc);
  84. Result:=RegisterBGIfont(@TriplexFontProc);
  85. Result:=RegisterBGIfont(@SmallFontProc);
  86. PriorExit:=ExitProc;
  87. ExitProc:=@Terminate;
  88. end;
  89.  
  90. procedure Inculcate;
  91.  
  92. type ColorType = 1..Colors;
  93.  
  94. var Hue: array[ColorType] of byte;
  95.  
  96. procedure Adjust;
  97.  
  98. const BackGround = 7;
  99.  
  100. var Index,
  101.     Cycle: ColorType;
  102.     Group: array[ColorType] of byte;
  103.  
  104. begin
  105. Randomize;
  106. SetBkColor(Random(Background));
  107. for Cycle:=1 to Colors
  108. do Group[Cycle]:=Cycle;
  109. for Cycle:=Colors downto 1
  110. do begin
  111.    Index:=Random(Cycle) + 1;
  112.    Hue[Cycle]:=Group[Index];
  113.    Move(Group[Index + 1], Group[Index], Colors - Index);
  114.    end;
  115. end;
  116.  
  117. const AtH = 159;
  118.       AtV = 66;
  119.       Offset = 40;
  120.       FontSize = 4;
  121.       TitleSize = 5;
  122.       NameSize = 1;
  123.  
  124. type Axes = (X,Y);
  125.      Pair = array[Axes] of shortint;
  126.  
  127. var Height,
  128.     Cycle: byte;
  129.  
  130. const Credit: string = 'Mandelbrot Set';
  131.       Shift: array[1..8] of Pair = ((-1,-1),(0,-1),(1,1),
  132.                                     (-1,0),(1,0),
  133.                                     (-1,1),(0,1),(1,1));
  134.  
  135. begin
  136. Adjust;
  137. SetColor(Hue[1]);
  138. SetTextJustify(CenterText, CenterText);
  139. SetTextStyle(GothicFont, HorizDir, TitleSize);
  140. for Cycle:=1 to 8
  141. do OutTextXY(AtH + Shift[Cycle][X], AtV + Shift[Cycle][Y], Credit);
  142. SetColor(Hue[2]);
  143. OutTextXY(AtH, AtV, Credit);
  144.  
  145. SetColor(Hue[3]);
  146. SetTextStyle(TriplexFont, HorizDir, FontSize);
  147. OutTextXY(AtH, AtV - Offset, 'GWNet');
  148.  
  149. SetTextStyle(DefaultFont, HorizDir, NameSize);
  150. OutTextXY(AtH, AtV + Offset, 'The Mad Programmer strikes again!');
  151. end;
  152.  
  153. var Seed: Shape;
  154.  
  155. procedure Anticipate;
  156.  
  157. procedure Respond;
  158.  
  159. const Escape = #27;
  160.  
  161. var Key: char;
  162.  
  163. begin
  164. while Keypressed
  165. do begin
  166.    Key:=ReadKey;
  167.    if Key=Escape
  168.    then Halt;
  169.    end;
  170. end;
  171.  
  172. type States = (Idle, Busy);
  173.  
  174. procedure Report(Now: States);
  175.  
  176. function NewHue: byte;
  177.  
  178. const Hue: byte = 0;
  179.  
  180. begin
  181. if Hue=Colors
  182. then Hue:=1
  183. else Inc(Hue);
  184. NewHue:=Hue;
  185. end;
  186.  
  187. const Off = 0;
  188.       Left = 0;
  189.       LowLine = 189;
  190.       FontSize = 4;
  191.  
  192. type Note = string[10];
  193.  
  194. const Message: array[States] of Note = ('waiting...',
  195.                                         'working...');
  196.  
  197. begin
  198. SetTextStyle(SmallFont, HorizDir, FontSize);
  199. SetTextJustify(LeftText, TopText);
  200. SetColor(Off);
  201. OutTextXY(Left, LowLine, Message[Pred(Now)]);
  202. SetColor(NewHue);
  203. OutTextXY(Left, LowLine, Message[Now]);
  204. end;
  205.  
  206. const Time = 500;
  207.  
  208. var Notice: file of Shape;
  209.  
  210. begin
  211. Report(Idle);
  212. Assign(Notice, Framework);
  213. FileMode:= Read_Write + Deny_None;
  214. repeat
  215.   Respond;
  216.   Delay(Time);
  217.   {$i-}
  218.   Reset(Notice);
  219.   {$i+}
  220. until (IOResult = No_Error);
  221. Read(Notice, Seed);
  222. Close(Notice);
  223. Report(Busy);
  224. end;
  225.  
  226. procedure Cultivate;
  227.  
  228. var Once: boolean;
  229.     Eye: file of Header;
  230.  
  231. function Work: boolean;
  232.  
  233. const Front = 0;
  234.  
  235. begin
  236. FileMode:=Read_Write + Deny_All;
  237. repeat
  238.   {$i-}
  239.   Reset(Eye);
  240.   {$i+}
  241. until (IOResult = No_Error);
  242. Read(Eye, Seed.Flux);
  243. Work:=false;
  244. with Seed
  245. do begin
  246.    if Once
  247.    then Dec(Flux.ToV);
  248.    if Flux.ToV = 0
  249.    then begin
  250.         Close(Eye);
  251.         repeat
  252.           Erase(Eye);
  253.         until (IOResult = No_Error);
  254.         end
  255.    else begin
  256.         if Flux.AtV > 0
  257.         then begin
  258.              Dec(Flux.AtV);
  259.              Work:=true;
  260.              end;
  261.         Seek(Eye, Front);
  262.         Write(Eye, Flux);
  263.         Close(Eye);
  264.         end;
  265.    end;
  266. end;
  267.  
  268. type Pixels = array[byte] of byte;
  269.      Count_Array = array[byte] of Count_Type;
  270.  
  271. var Span,
  272.     Base,
  273.     Scale,
  274.     Middle: word;
  275.     Map: real;
  276.     Innate: ^Pixels;
  277.     Zone: ^Count_Array;
  278.     Canvas: file;
  279.  
  280. procedure Prepare;
  281.  
  282. var Range: word;
  283.  
  284. const Height = 200;
  285.  
  286. begin
  287. Assign(Eye, Framework);
  288. Assign(Canvas, Painting);
  289. with Seed
  290. do begin
  291.    Middle:=V div 2;
  292.    Map:=Height / V;
  293.    Range:=(Treble - Bass) div Choir;
  294.    Scale:=Range div Most;
  295.    Base:=Bass + Range * Random(Choir);
  296.    Span:=SizeOf(Count_Type) * H;
  297.    GetMem(Zone, Span);
  298.    GetMem(Innate, ByteLine);
  299.    FileMode:=Write_Only + Deny_None;
  300.    Reset(Canvas, ByteLine);
  301.    end;
  302. SetWriteMode(XORPut);
  303. SetColor(Random(Colors) + 1);
  304. end;
  305.  
  306. procedure Conclude;
  307.  
  308. begin
  309. Close(Canvas);
  310. FreeMem(Zone, Span);
  311. FreeMem(Innate, Seed.ByteLine);
  312. SetWriteMode(NormalPut);
  313. ClearDevice;
  314. end;
  315.  
  316. procedure Abandon;
  317.  
  318. var Key: char;
  319.  
  320. begin
  321. NoSound;
  322. Conclude;
  323. while KeyPressed
  324. do Key:=ReadKey;
  325. Halt;
  326. end;
  327.  
  328. procedure Develop;
  329.  
  330. procedure Convert;
  331.  
  332. var Merge,
  333.     Inner: byte;
  334.     Cycle: word;
  335.     Index: Size_Type;
  336.  
  337. begin
  338. Cycle:=0;
  339. Index:=Seed.H;
  340. with Seed
  341. do repeat
  342.      for Inner:=1 to PixelByte
  343.      do begin
  344.     Merge:=Merge shl BitPixel or (Most - Zone^[Index]);
  345.     Dec(Index);
  346.         end;
  347.      Innate^[Cycle]:=Merge;
  348.      Inc(Cycle);
  349.    until Cycle=ByteLine;
  350. end;
  351.  
  352. procedure Gauge;
  353.  
  354. const Left= 0;
  355.       Right= 319;
  356.  
  357. const Fore: word = 0;
  358.       Rear: word = 0;
  359.       PreFore: word = 0;
  360.       PreRear: word = 0;
  361.  
  362. begin
  363. with Seed.Flux
  364. do begin
  365.    if Once
  366.    then Rectangle(Left, PreFore, Right, PreRear);
  367.    Fore:=Trunc(AtV * Map);
  368.    Rear:=Trunc(ToV * Map);
  369.    end;
  370. Rectangle(Left, Fore, Right, Rear);
  371. PreFore:=Fore;
  372. PreRear:=Rear;
  373. end;
  374.  
  375. var Offset: word;
  376.  
  377. const Single = 1;
  378.  
  379. begin
  380. Convert;
  381. with Seed
  382. do if Interlace
  383.    then begin
  384.         Offset:=Flux.AtV div 2;
  385.         if Odd(Flux.AtV)
  386.         then Seek(Canvas, Middle + Offset)
  387.         else Seek(Canvas, Offset)
  388.         end
  389.    else Seek(Canvas, Flux.AtV);
  390. BlockWrite(Canvas, Innate^, Single);
  391. Gauge;
  392. end;
  393.  
  394. var ZR,
  395.     ZI,
  396.     ZR2,
  397.     ZI2: Real_Type;
  398.  
  399. function Chaotic:boolean;
  400.  
  401. begin
  402. ZR2:=ZR * ZR;
  403. ZI2:=ZI * ZI;
  404. Chaotic:=(ZR2 + ZI2 < 4);
  405. end;
  406.  
  407. var I: Count_Type;
  408.  
  409. function Note: word;
  410.  
  411. begin
  412. Note:=Trunc(Base + I * Scale);
  413. end;
  414.  
  415. procedure Sing;
  416.  
  417. const Cycle: word = 0;
  418.       Duration: word = 0;
  419.  
  420. begin
  421. Inc(Cycle);
  422. if Cycle=Rhythm
  423. then begin
  424.      Cycle:=0;
  425.      Duration:=(Rhythm shr Tempo) shl Random(Tempo);
  426.      Sound(Note);
  427.      end;
  428. if Cycle = Duration
  429. then NoSound;
  430. end;
  431.  
  432. var X: Size_Type;
  433.     CR,
  434.     CI: Real_Type;
  435.  
  436. begin
  437. Prepare;
  438. Once:=false;
  439. while Work
  440. do with Seed
  441.    do begin
  442.       X:=H;
  443.       CR:=Left;
  444.       CI:=Top - (Flux.AtV * YInc);
  445.       repeat
  446.          ZR:=CR;
  447.          ZI:=CI;
  448.          I:=1;
  449.          while Chaotic and (I < Most)
  450.          do begin
  451.             ZR:=ZR2 - ZI2 + CR;
  452.             ZI:=2 * ZR * ZI + CI;
  453.             Inc(I);
  454.             end;
  455.          Dec(X);
  456.          Zone^[X]:=I;
  457.          CR:=CR + XInc;
  458.          if Flux.Sound
  459.          then Sing;
  460.       until (X=0);
  461.       Develop;
  462.       if KeyPressed
  463.       then Abandon;
  464.       Once:=true;
  465.       end;
  466. Conclude;
  467. end;
  468.  
  469. const EndOfTime = false;
  470.  
  471. begin
  472. Initiate;
  473. repeat
  474.   Inculcate;
  475.   Anticipate;
  476.   Cultivate;
  477. until EndOfTime;
  478. {Terminate;}
  479. end.